package jwdt.xadmin.work.service.impl;

import jwdt.common.dao.BaseDao;
import jwdt.xadmin.system.bean.TUser;
import jwdt.xadmin.work.bean.TWorkLog;
import jwdt.xadmin.work.service.WorkLogManageService;

import com.ezerg.db.ext.PageUtil;
import com.ezerg.util.DateUtil;
import com.ezerg.util.StringUtil;

public class WorkLogManageServiceImpl implements WorkLogManageService{

	private BaseDao<TWorkLog> baseDao;
	
	public void setBaseDao(BaseDao<TWorkLog> baseDao) {
		this.baseDao = baseDao;
	}

	@Override
	public PageUtil doList(PageUtil pu,TWorkLog obj,TUser userInfo) throws Exception{
		String where = "1=1";
		Integer userId = userInfo.getUserid();
		if(userId != null) {
			where += " and userid = " + userId;
		}
		Integer projectId = obj.getProjectid();
		String starttime = obj.getDt();
		String endtime = obj.getContent();
		if(projectId !=null){
			where += " and projectid = "+ projectId;
		}
		if(!StringUtil.nullOrBlank(starttime) && !StringUtil.nullOrBlank(endtime)){
			where += " AND (dt BETWEEN '"+starttime+"' AND '"+endtime+"')";
		}
		String sql = where+" order by dt desc";
		pu.doList(TWorkLog.class,sql);
		//创造json数据对象
		return pu;
	}

	@Override
	public String doAddact(TWorkLog obj,TUser userInfo) throws Exception {
		obj.setDt(DateUtil.getDateTime());
		obj.setUserid(userInfo.getUserid());
		return baseDao.doAddObj(obj);
	}

	@Override
	public String doEditact(TWorkLog obj, int id) throws Exception {
		return baseDao.doUpdateObj(TWorkLog.class, id, obj);
	}
	
	@Override
	public String doDelact(int id) throws Exception {
		String ret = baseDao.doDelObj(TWorkLog.class, id);
		return ret;
	}

	@Override
	public TWorkLog doLoad(int logid) throws Exception {
		return baseDao.doLoadObj(TWorkLog.class, logid);
	}
}
